﻿//-----------------------------------------------------------------------
// <copyright file="LogOnCommand.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//-----------------------------------------------------------------------

namespace ChatBox.UI.Windows.Main
{
    using ChatBox.UI.Commands;

    /// <summary>
    /// Command to log on the engine
    /// </summary>
    public class LogOnCommand : GenericCommandBase<MainWindowViewModel>
    {
        /// <summary>
        /// Execute the log-on command
        /// </summary>
        /// <param name="value">the command data</param>
        public override void ExecuteOnValue(MainWindowViewModel value)
        {
            if (value == null)
            {
                return;
            }

            if (value.IsLoggedOn)
            {
                return;
            }

            // check that basic setup is in place
            if (! value.CheckNameAndPassword("log on"))
            {
                return;
            }

            value.ChatEngine.LogOn();
        }

        /// <summary>
        /// Can the command execute
        /// </summary>
        /// <param name="value">the view model to inspect</param>
        /// <returns>true if the command can execute</returns>
        public override bool CanExecuteOnValue(MainWindowViewModel value)
        {
            return (value != null) && (!value.IsLoggedOn);
        }
    }
}
